﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DbGenerator.Model.units.column;
using Unity.Errors.types;
using Unity.Logic.Expressions.statements;

namespace DbExecuter.DataLayer.commands
{
    public class TWhereClause
    {
        #region ctors
        public TWhereClause(TWhereColumn[] whereColumns, TCommandParameter[] whereParameters)
        {
            _WhereColumns = whereColumns;
            _WhereParameters = whereParameters;
            _ParameterCount = _WhereColumns.Length;
        }
        #endregion

        #region overriden methods
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("WHERE ");
            for (int i = 0; i < _ParameterCount; i++)
            {
                sb.AppendFormat("\n\t({0}.[{1}] {3} {4})"
                    , _WhereColumns[i].BaseColumn.ColumnAlias
                    , _WhereColumns[i].BaseColumn.ColumnInfo.ColumnName
                    , TStatementBase.RelationsDict[_WhereColumns[i].Relation]
                    , _WhereParameters[i].ParameterName);
            }
            return sb.ToString();
        }
        #endregion

        #region properties
        private TWhereColumn[] _WhereColumns;
        public TWhereColumn[] WhereColumns
        {
            get { return _WhereColumns; }
        }

        private TCommandParameter[] _WhereParameters;
        public TCommandParameter[] WhereParameters
        {
            get { return _WhereParameters; }
        }
        private int _ParameterCount;
        public int ParameterCount
        {
            get { return _ParameterCount; }
        }
        #endregion
    }
}
